<?php
$form = $this->form;
$form->prepare();
$form->setAttribute('action', $this->url('admin/user/update' , array('id' => $user_id)));
$form->setAttribute('method', 'post');
$form->setAttribute('class' , 'form-horizontal');
?>
<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-blue">
            <div class="panel-heading">
                <?php echo $this->translate('Create User');?>
            </div>
            <div class="panel-body pan">

            </div>
            <?php if(count($flashMessages)): ?>
                <?php foreach ($flashMessages as $msg) : ?>
                    <div class="alert alert-block alert-success">
                        <a class="close" data-dismiss="alert" href="#">×</a>
                        <p><?php echo $this->translate($msg) ?></p>
                    </div>
                <?php endforeach; ?>
            <?php endif; ?>

            <?php echo $this->form()->openTag($form); ?>
            <div class="form-body pal">
            <?php foreach ($form as $element): ?>
                <?php if($element instanceof Admin\Form\CreateUserFieldset): ?>
                    <?php foreach ($element as $userElement): ?>
                        <?php if($userElement instanceof Admin\Form\RoleUserFieldset): ?>
                            <?php foreach ($userElement as $roleUserFieldsetElement): ?>
                                <div class="form-group <?php echo ($this->formElementErrors($roleUserFieldsetElement)) ? 'has-error' : '' ; ?>">
                                    <div class="col-md-3 control-label">
                                        <label for="<?php echo $this->translate($roleUserFieldsetElement->getName());?>">
                                            <?php echo $roleUserFieldsetElement->getLabel(); ?>
                                        </label>
                                    </div>
                                    <?php //echo $this->formLabel($element); ?>
                                    <div class="col-md-9">
                                        <?php if ($roleUserFieldsetElement instanceof Zend\Form\Element\Select): ?>
                                            <?php echo $this->formSelect($roleUserFieldsetElement); ?>
                                        <?php else: ?>
                                            <?php echo $this->formInput($roleUserFieldsetElement); ?>
                                        <?php endif; ?>
                                        <div class="col-md-12">
                                            <div class="help-block">
                                                <div class="row">
                                                    <?php echo $this->translate($this->formElementErrors($roleUserFieldsetElement)); ?>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            <?php endforeach; ?>
                        <?php elseif($userElement instanceof Admin\Form\AvatarUserFieldset): ?>
                            <?php foreach ($userElement as $avatarUserFieldset): ?>
                                <div class="form-group <?php echo ($this->formElementErrors($roleUserFieldsetElement)) ? 'has-error' : '' ; ?>">
                                    <div class="col-md-3 control-label">
                                        <label for="<?php echo $this->translate($avatarUserFieldset->getName());?>">
                                            <?php echo $avatarUserFieldset->getLabel(); ?>
                                        </label>
                                    </div>
                                    <?php //echo $this->formLabel($element); ?>
                                    <div class="col-md-9">
                                        <?php if ($avatarUserFieldset instanceof Zend\Form\Element\File): ?>
                                            <?php echo $this->formFile($avatarUserFieldset); ?>
                                        <?php else: ?>
                                            <?php echo $this->formInput($avatarUserFieldset); ?>
                                        <?php endif; ?>
                                        <div class="col-md-12">
                                            <div class="help-block">
                                                <div class="row">
                                                    <?php echo $this->translate($this->formElementErrors($avatarUserFieldset)); ?>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            <?php endforeach; ?>
                        <?php else: ?>
                            <div class="form-group <?php echo ($this->formElementErrors($userElement)) ? 'has-error' : '' ; ?>">
                                <div class="col-md-3 control-label">
                                    <label for="<?php echo $this->translate($userElement->getName());?>">
                                        <?php echo $userElement->getLabel(); ?>
                                    </label>
                                </div>
                                <?php //echo $this->formLabel($element); ?>
                                <div class="col-md-9">
                                    <?php if ($userElement instanceof Zend\Form\Element\Select): ?>
                                        <?php echo $this->formSelect($userElement); ?>
                                    <?php elseif ($userElement instanceof Zend\Form\Element\File):  ?>
                                        <?php echo $this->formFile($userElement); ?>
                                    <?php else:  ?>
                                        <?php echo $this->formInput($userElement); ?>
                                    <?php endif; ?>
                                    <div class="col-md-12">
                                        <div class="help-block">
                                            <div class="row">
                                                <?php echo $this->translate($this->formElementErrors($userElement)); ?>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        <?php endif; ?>
                    <?php endforeach;?>
                <?php elseif($element instanceof Admin\Form\RoleUserFieldset): ?>
                    <div class="form-group col-md-8 col-sm-3 col-md-offset-2 <?php echo ($this->formElementErrors($element)) ? 'has-error' : '' ; ?>">
                        <div class="col-md-3 control-label">
                            <label for="<?php echo $this->translate($element->getName());?>">
                                <?php echo $element->getLabel(); ?>
                            </label>
                        </div>
                        <?php //echo $this->formLabel($element); ?>
                        <div class="col-md-9">
                            <?php if ($element instanceof Zend\Form\Element\Select): ?>
                                <?php echo $this->formSelect($element->get('role_id')); ?>
                            <?php else: ?>
                                <?php echo $this->formSelect($element->get('role_id')); ?>
                            <?php endif; ?>
                            <div class="col-md-12">
                                <div class="help-block">
                                    <div class="row">
                                        <?php echo $this->translate($this->formElementErrors($element)); ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                <?php endif;?>
            <?php endforeach; ?>
            <?php if ($this->redirect): ?>
            <input type="hidden" name="redirect" value="<?php echo $this->escapeHtml($this->redirect) ?>" />
            <?php endif ?>
            </div>
            <div class="form-actions">
                <div class="col-md-offset-3 col-md-9">
                    <?php echo $this->formButton($element) ?>
                </div>
            </div>

            <?php echo $this->form()->closeTag(); ?>
        </div>
    </div>
</div>